package com.ant.storage.controller;
import com.ant.storage.common.PageRequest;
import com.ant.storage.common.ResultCode;
import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.GoodsUnits;
import com.ant.storage.service.IGoodsUnitsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/goodsUnits")
@Api(tags = "计量单位接口")
public class GoodsUnitsController {

    @Autowired
    private IGoodsUnitsService goodsUnitsService;
    @ApiOperation(value = "获取计量单位分页数据")
    @GetMapping("/getGoodsUnitsPage")
    public ResultPage getGoodsUnitsPage(PageRequest pageRequest) {
        return ResultPage.success("获取成功",goodsUnitsService.queryPages(pageRequest));
    }
    @ApiOperation(value = "获取计量单位数据列表")
    @GetMapping("/getGoodsUnitsList")
    public ResultVo getGoodsUnitsList() {
        return ResultVo.success("获取成功",goodsUnitsService.list());
    }

    @ApiOperation(value = "添加计量单位")
    @PostMapping("/addGoodsUnits")
    public ResultVo addGoodsUnits(@RequestBody GoodsUnits goodsUnits) {
        if(StringUtils.isEmpty(goodsUnits.getUnits())){
            throw new AntException(ResultCode.PARAM_IS_BLANK.getResultCode(),"名称不能为空");
        }else{
            if(goodsUnits.getId()==null){
                goodsUnitsService.save(goodsUnits);
                return ResultVo.success("添加成功");
            }else{
                goodsUnitsService.updateById(goodsUnits);
                return ResultVo.success("修改成功");
            }
        }
    }

    public static void main(String[] args) {
        Calendar now = Calendar.getInstance(); // 获取当前时间
        Calendar target = Calendar.getInstance(); // 获取指定时间

        // 设置指定时间为2022年1月1日下午3点30分0秒
        target.set(Calendar.YEAR, 2024);
        target.set(Calendar.MONTH, Calendar.JANUARY);
        target.set(Calendar.DAY_OF_MONTH, 12);
        target.set(Calendar.HOUR_OF_DAY, 7);
        target.set(Calendar.MINUTE, 30);
        target.set(Calendar.SECOND, 0);

        // 比较当前时间和指定时间
        if (now.after(target)) {
            System.out.println("当前时间晚于指定时间");
        } else {
            System.out.println("当前时间早于指定时间");
        }

    }

}
